/*
 * @(#)WorkflowSchedule.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.bean;

import java.sql.Timestamp;

import com.dcivision.framework.bean.AbstractBaseObject;

/**
 * WorkflowSchedule.java
 * 
 * This class is the serializable bean reflecting business logic uses.
 * It acts as an abstract of representing a schedule. Currently, four schedule
 * types are supported, respectively once, daily, weekly and monthly. Except
 * the trigger once, each types can be further defined with different styles.
 * 
 * @author Lun Au
 * @company DCIVision Limited
 * @creation date 18/12/2004
 * @version $Revision: 1.6 $
 * @see com.dcivision.workflow.bean.WorkflowScheduleTriggers
 * @see com.dcivision.workflow.core.TriggerParser
 */
public class WorkflowSchedule extends AbstractBaseObject {
  
  static final long serialVersionUID = -8321121235978810302L;
  
  // Define constant for schedule type
  /** Trigger only once */
  public static final transient int TRIGGER_TYPE_ONCE = 0;
  /** Trigger daily */
  public static final transient int TRIGGER_TYPE_DAILY = 1;
  /** Trigger weekly */
  public static final transient int TRIGGER_TYPE_WEEKLY = 2;
  /** Trigger monthly */
  public static final transient int TRIGGER_TYPE_MONTHLY = 3;
  /** Currently not supported, for future use */
  public static final transient int TRIGGER_TYPE_YEARLY = 4;
  
  // Define constant for schedule style for each type
  
  // Daily styles
  /** Daily style, trigger everyday */
  public static final transient int DAILY_STYLE_EVERYDAY = 10;
  /** Daily style, trigger every weekdays */
  public static final transient int DAILY_STYLE_WEEKDAYS = 11;
  /** Daily style, trigger per N days */
  public static final transient int DAILY_STYLE_INTERVAL = 12;
  
  // Weekly styles
  /** Weekly style, trigger per N weeks */
  public static final transient int WEEKLY_STYLE_INTERVAL = 20;
  
  // Monthly styles
  /** Monthly style, trigger at every N-th day of month */
  public static final transient int MONHTLY_STYLE_DAY_OF_MONTH = 30;
  /** Monthly style, trigger at every N-th week of month */
  public static final transient int MONHTLY_STYLE_WEEK_OF_MONTH = 31;
  
  // End of schedule
  /** Indicates this schedule will never end */
  public static final transient int END_STYLE_NONE = 90;
  /** Indicates this schedule will end after N triggers */
  public static final transient int END_STYLE_COUNT = 91;
  /** Indicates this schedule will end after a certain date */
  public static final transient int END_STYLE_DATE = 92;
  
  // Special characters for cron job expression
  public static final transient String EXPR_SPECIAL_ALL = "*";
  public static final transient String EXPR_SPECIAL_OTHER = "?";
  public static final transient String EXPR_SPECIAL_LAST = "L";
  public static final transient String EXPR_SPECIAL_N = "#";
  public static final transient String EXPR_SPECIAL_INCREMENT = "/";
  public static final transient String EXPR_SPECIAL_ADDITIONAL = ",";
  
  // Schedule Trigger Status
  public static final String SCHEDULE_TRIGGER_PENDING_STATUS = "P";
  public static final String SCHEDULE_TRIGGER_RELEASED_STATUS = "R";  
  public static final String SCHEDULE_TRIGGER_CANCEL_STATUS = "C";
  public static final String SCHEDULE_TRIGGER_EXPIRE_STATUS = "E";
  public static final String SCHEDULE_TRIGGER_IN_PROGRESS_STATUS = "I";
  
  //--- Start of bean property ---
  private int maxRun = -1;
  private int currentRun = 0;
  private Timestamp startDate;
  private Timestamp endDate;
  
  private String triggerName;
  private int triggerType = TRIGGER_TYPE_ONCE;
  private int triggerStyle;
  
  // For the trigger time of all trigger type
  private int triggerHour;
  private int triggerMinute;
  
  // For WEEKLY_STYLE_INTERVAL or DAILY_STYLE_INTERVAL
  private int interval = 1;
  
  // For weekly general
  private String daysOfWeek[] = new String[]{"1","2","3","4","5","6","7"};
  
  // For MONTLY_STYLE_DAY_OF_MONTH
  private String dayOfMonth = null;
  // For MONTLY_STYLE_WEEK_OF_MONTH
  private String weekOfMonth = null;
  private String dayOfWeek = null;
  // For monthly general
  private String monthsOfYear[] = new String[]{"1","2","3","4","5","6","7","8","9","10","11","12"};
  
  //--- End of bean property
  
  /**
   * @return Returns the currentRun.
   */
  public int getCurrentRun() {
    return currentRun;
  }
  
  /**
   * @param currentRun The currentRun to set.
   */
  public void setCurrentRun(int currentRun) {
    this.currentRun = currentRun;
  }
  
  /**
   * @return Returns the dayOfMonth.
   */
  public String getDayOfMonth() {
    return dayOfMonth;
  }
  
  /**
   * @param dayOfMonth The dayOfMonth to set.
   */
  public void setDayOfMonth(String dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
  }
  
  /**
   * @return Returns the dayOfWeek.
   */
  public String getDayOfWeek() {
    return dayOfWeek;
  }
  
  /**
   * @param dayOfWeek The dayOfWeek to set.
   */
  public void setDayOfWeek(String dayOfWeek) {
    this.dayOfWeek = dayOfWeek;
  }
  
  /**
   * @return Returns the daysOfWeek.
   */
  public String[] getDaysOfWeek() {
    return daysOfWeek;
  }
  
  /**
   * @param daysOfWeek The daysOfWeek to set.
   */
  public void setDaysOfWeek(String[] daysOfWeek) {
    this.daysOfWeek = daysOfWeek;
  }
  
  /**
   * @return Returns the endDate.
   */
  public Timestamp getEndDate() {
    return endDate;
  }
  
  /**
   * @param endDate The endDate to set.
   */
  public void setEndDate(Timestamp endDate) {
    this.endDate = endDate;
  }
  
  /**
   * @return Returns the interval.
   */
  public int getInterval() {
    return interval;
  }
  
  /**
   * @param interval The interval to set.
   */
  public void setInterval(int interval) {
    this.interval = interval;
  }
  
  /**
   * @return Returns the maxRun.
   */
  public int getMaxRun() {
    return maxRun;
  }
  
  /**
   * @param maxRun The maxRun to set.
   */
  public void setMaxRun(int maxRun) {
    this.maxRun = maxRun;
  }
  
  /**
   * @return Returns the monthsOfYear.
   */
  public String[] getMonthsOfYear() {
    return monthsOfYear;
  }
  
  /**
   * @param monthsOfYear The monthsOfYear to set.
   */
  public void setMonthsOfYear(String[] monthsOfYear) {
    this.monthsOfYear = monthsOfYear;
  }
  
  /**
   * @return Returns the startDate.
   */
  public Timestamp getStartDate() {
    return startDate;
  }
  
  /**
   * @param startDate The startDate to set.
   */
  public void setStartDate(Timestamp startDate) {
    this.startDate = startDate;
  }
  
  /**
   * @return Returns the triggerHour.
   */
  public int getTriggerHour() {
    return triggerHour;
  }
  
  /**
   * @param triggerHour The triggerHour to set.
   */
  public void setTriggerHour(int triggerHour) {
    this.triggerHour = triggerHour;
  }
  
  /**
   * @return Returns the triggerMinute.
   */
  public int getTriggerMinute() {
    return triggerMinute;
  }
  
  /**
   * @param triggerMinute The triggerMinute to set.
   */
  public void setTriggerMinute(int triggerMinute) {
    this.triggerMinute = triggerMinute;
  }
  
  /**
   * @return Returns the triggerName.
   */
  public String getTriggerName() {
    return triggerName;
  }
  
  /**
   * @param triggerName The triggerName to set.
   */
  public void setTriggerName(String triggerName) {
    this.triggerName = triggerName;
  }
  
  /**
   * @return Returns the triggerStyle.
   */
  public int getTriggerStyle() {
    return triggerStyle;
  }
  
  /**
   * @param triggerStyle The triggerStyle to set.
   */
  public void setTriggerStyle(int triggerStyle) {
    this.triggerStyle = triggerStyle;
  }
  
  /**
   * @return Returns the triggerType.
   */
  public int getTriggerType() {
    return triggerType;
  }
  
  /**
   * @param triggerType The triggerType to set.
   */
  public void setTriggerType(int triggerType) {
    this.triggerType = triggerType;
  }
  
  /**
   * @return Returns the weekOfMonth.
   */
  public String getWeekOfMonth() {
    return weekOfMonth;
  }
  
  /**
   * @param weekOfMonth The weekOfMonth to set.
   */
  public void setWeekOfMonth(String weekOfMonth) {
    this.weekOfMonth = weekOfMonth;
  }
}
